package com.atguigu.gulimaill.cart.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program: gulimall
 * @description: 线程池
 * @author: liuxvru
 * @create: 2024-08-25 19:17
 **/
@ConfigurationProperties(prefix = "gulimall.thread")
@Data
@Configuration
public class MyThreadConfig {

    private Integer coreSize;
    private Integer maxSize;
    private Integer keepAliveTime;
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(coreSize,
                maxSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(10000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }
}
